package portal.web.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import portal.vo.ProductoVO;
import portal.web.businessDelegate.PortalComprasDelegate;

@SuppressWarnings("serial")
public class ObtenerDetalleServlet extends HttpServlet {

	private static Logger logger = Logger.getLogger(ObtenerDetalleServlet.class);

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		processRequest(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		processRequest(req, resp);
	}

	private void processRequest(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		logger.debug(">>>>>>>>>>>>>>>>>>>>>>>>>>ObtenerDetalleServlet<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		
		Long idProducto = Long.parseLong((String)req.getParameter("id"));
		
		logger.debug("Id:" + idProducto);
		
		ProductoVO producto = PortalComprasDelegate.getInstance().getProductoById(idProducto);
		
		req.setAttribute("producto", producto);

		req.getRequestDispatcher("/jsp/detalleProductos.jsp").forward(req, resp);

	}
}
